package com.luguz.controller;

import com.luguz.common.Result;
import com.luguz.common.weather.WeatherData;
import com.luguz.common.weather.WeatherForecast;
import com.luguz.util.getWeatherInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author Guz
 * @create 2022-02--26 20:29
 */
@RestController
public class WeatherController {
    @GetMapping("/api/getWeather/{city}")
    public Object getWeather(@PathVariable("city") String city) throws IOException {
        WeatherForecast weatherForecast = (WeatherForecast) getWeatherInfo.getWeatherInform(city);
        if(weatherForecast == null){
            return Result.fail("没有找到当前城市");
        }
        return Result.succ(weatherForecast);
    }
}
